from django.shortcuts import render
from django.views import View

from apps.goods.models import GoodsChannel
from apps.goods.utils import get_categories
from apps.index.models import ContentCategory


class IndexView(View):

    def get(self, request):
        """
        主页
        :param request:
        :return:
        """
        # 获取商品分类
        categories = get_categories()

        # pprint(categories_dict)

        # 广告数据, 推广信息
        contents = {}
        content_categories = ContentCategory.objects.all()
        for temp in content_categories:
            contents[temp.key] = temp.content_set.filter(status=True).order_by('sequence')

        # 渲染模板的上下文
        context = {
            'categories': categories,
            'contents': contents,
        }

        return render(request, 'index_test.html', context)



